<?php
/*
 * Created on Jun 12, 2007
 *
 * Define a custom exception class
 */

// some code constant

if(!defined("EXCEPTION_FATAL_DB")) {
   define("EXCEPTION_FATAL_DB", 1);
}
 
if(!defined("EXCEPTION_ERROR_DB_QUERY")) {
   define("EXCEPTION_ERROR_DB_QUERY", 2);
}

if(!defined("EXCEPTION_ERROR_DB_FETCH")) {
   define("EXCEPTION_ERROR_DB_FETCH", 3);
}

if(!defined("EXCEPTION_WARNING_DB_NUMROWS")) {
   define("EXCEPTION_WARNING_DB_NUMROWS", 4);
}

/* 
 * the exception handler.
 * We may want to redirect to an error page...
 */
function exception_handler($e) {
   echo 'Sorry, an unpredictable error occured. Please go back and retry<br /> Message is: '.$e->getMessage();
   // header("")
   // TODO send an email to the programmers...us!
  }

// sets exception handler
set_exception_handler('exception_handler');

class MTException extends Exception
{
  private $debugMsg;
  
  public function MTException($message=null, $code = null, $debugMsg = null) {
  	
    parent::__construct($message, $code);
    $this->debugMsg = $debugMsg;
    
    // if the exception has a
    // debug mesg, we log it
    //if($debugMsg)
      //Logger::getInstance()->logException($this->getFile().', line '.$this->getLine()." $debugMsg - ($message)");
  }
  
  // custom string representation of object
  public function __toString() {
    return $this->message;
  }
  
  public function setMsg($msg){
  	$this->message = $msg;
  }
  
  public function setCode($code){
  	$this->code = $code;
  }
  
  public function getDebugMsg(){
  	return __CLASS__ . ': ' .$this->debugMsg;
  }
  
}
 
?>
